    var appid="",auth="ssssss";
    // var ApiUrl="http://188110l7r2.iok.la:46273";
    var ApiUrl="http://bosiny.imwork.net:10632";
    // var ApiUrl="http://192.168.2.233";

    // var appid = GetQueryString("appid");
    // if(isEmpty(appid)){
    //     appid = getcookie("appid");
    //     if(isEmpty(appid))
    //         error("缺少appid");
    // }
    addcookie('appid', appid, 30*24);
    function error(msg){
        addcookie("sys_msg",msg,1);
        location.href = "error.html";
    }
    function isEmpty(s){
        if(s == undefined || s ==null || s == "")
            return true;
        return false;
    }

    function getUrlParam(url,name) {
        var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
        var matcher = pattern.exec(url);
        var items = null;
        if(null != matcher){
            try{
                items = decodeURIComponent(decodeURIComponent(matcher[1]));
            }catch(e){
                try{
                    items = decodeURIComponent(matcher[1]);
                }catch(e){
                    items = matcher[1];
                }
            }
        }
        return items;
    }
    //-------获取路径参数的方法----------
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r!=null) return unescape(r[2]);
        return null;
    }

    function addcookie(name,value,expireHours){
        var cookieString=name+"="+escape(value)+"; path=/";
        //判断是否设置过期时间
        if(expireHours>0){
            var date=new Date();
            date.setTime(date.getTime+expireHours*3600*1000);
            cookieString=cookieString+"; expire="+date.toGMTString();
        }
        document.cookie=cookieString;
    }

    function getcookie(name){
        var strcookie=document.cookie;
        var arrcookie=strcookie.split("; ");
        for(var i=0;i<arrcookie.length;i++){
            var arr=arrcookie[i].split("=");
            if(arr[0]==name)return decodeURIComponent(arr[1]); //增加对特殊字符的解析
        }
        return "";
    }

    function delCookie(name){//删除cookie
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval=getcookie(name);
        if(cval!=null) document.cookie= name + "="+cval+"; path=/;expires="+exp.toGMTString();
    }

    // 判断浏览器类型
    if (/MicroMessenger/.test(window.navigator.userAgent)) {
        wxopenid();
    } else if (/AlipayClient/.test(window.navigator.userAgent)) {

        // aliuserid();
    } else {
        // alert('其他浏览器');
    }

    //---------------------微信浏览器授权获取openid begin-------------------------
    function wxopenid() {
        var wxopenid = getcookie('wxopenid');
        var access_code = GetQueryString('code');

        if (isEmpty(wxopenid)) {
            if (isEmpty(access_code)) {
                var fromurl = location.href;
                addcookie('redirect_uri', fromurl, 360000);
                // wxbc26bda7ccc6e744
                // var url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx54b509f51c66ceb8&redirect_uri=' + encodeURIComponent(fromurl) + '&response_type=code&scope=snsapi_base&state=STATE%23wechat_redirect&connect_redirect=1#wechat_redirect';
                var url = ApiUrl+'/api/auth/forward?payChannel=WeChatPay&appid='+appid+'&uri=' + encodeURIComponent(fromurl)
                location.href = url;
            }
            else {
                var url = ApiUrl+'/api/js/openid?code='+access_code;
                $.ajax({
                    type: 'get',
                    url: url,
                    async: true,
                    cache: false,
                    headers:{"appid":appid,"authorization":auth},
                    dataType: 'json',
                    success: function (result) {
                        console.log(result)
                        if (result != null && result.data.hasOwnProperty('openid') && result.data.openid != "") {
                            addcookie('wxopenid', result.data.openid, 360000);
                            var fromurl=getcookie("redirect_uri");
                            if(!isEmpty(fromurl))
                            {
                                location.href=fromurl;
                            }
                        }
                        else {
                            alert('微信身份识别失败 \n ' + JSON.stringify(result));
                        }
                    },
                    error:function (res) {
                        alert(JSON.stringify(res))
                    }
                });
            }
        }
    }
    //---------------------微信浏览器end-------------------------
